﻿@inject IEntryService _entryService
@implements IDisposable
@inject IDataCacheService _dataCacheService

<div>
    <div>@($"{item.SubName} -> {item.HostName} ({index}/{Model.Count})")</div>
    <MProgressLinear Value="index*100.0/Model.Count" Class="mb-2" Stream BufferValue="0" ></MProgressLinear>
</div>
<div>
    <div>@($"{infor} ({item.CompleteTaskCount}/{item.TotalTaskCount})")</div>
    <MProgressLinear Value="item.CompleteTaskCount*100.0/item.TotalTaskCount" Stream BufferValue="0" ></MProgressLinear>
</div>

@code {
    [Parameter]
    public List<MergeEntryModel> Model { get; set; }
    [Parameter]
    public string Class { get; set; }

    int index = 0;
    string infor = "";
    MergeEntryModel item = new MergeEntryModel();

    public async void OnProgressUpdate(KeyValuePair<OutputLevel, string> model)
    {

        try
        {
            await InvokeAsync(() =>
            {
                infor = model.Value;
                StateHasChanged();
            });
        }
        catch
        {

        }
    }

    public async Task Proc()
    {
        _entryService.ProgressUpdate += OnProgressUpdate;

        for (index = 0; index < Model.Count; index++)
        {
            item = Model[index];
            await _entryService.ProcMergeEntry(item);
        }

        _entryService.ProgressUpdate -= OnProgressUpdate;
    }

    #region 释放实例
    public void Dispose()
    {
        _entryService.ProgressUpdate -= OnProgressUpdate;
        GC.SuppressFinalize(this);
    }
    #endregion

}
